package com.lindenvalley.de.parsers;

import java.io.InputStream;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

public class SimpleXmlParser<T>  {
	
	private Class<T> ob;
	private Serializer serializer;
	private T result;

	public SimpleXmlParser(Class<T> ob) {
		super();		
		this.ob = ob;
		serializer = new Persister();
	}
	
	public T parse(String data) {
		
		result = null;
		try {
			result = (T) serializer.read(ob.newInstance(), data);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}
	
	public T parse(InputStream is){
		result = null;
		try {
			result = (T) serializer.read(ob.newInstance(), is);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
